package com.kidback.bbloc259.ui.home;

import android.view.View;
import android.view.ViewGroup;

import com.kidback.bbloc259.app.provider.UserDataProvider;
import com.kidback.bbloc259.base.BaseFragment;
import com.kidback.bbloc259.databinding.HomeFragmentBinding;
import com.kidback.bbloc259.event.UserLocEvent;
import com.kidback.bbloc259.ui.NotificationActivity;
import com.kidback.bbloc259.ui.view.ViewActivity;
import com.kidback.bbloc259.util.ActivityLaunchUtils;
import com.kidback.bbloc259.util.TimeUtils;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class HomeFragment extends BaseFragment<HomeFragmentBinding> {

    @Override
    public HomeFragmentBinding getViewBinding(ViewGroup container) {
        return HomeFragmentBinding.inflate(inflater);
    }

    @Override
    protected void initView() {

        if (UserDataProvider.getInst().hasUserData()) {

        } else {

        }

        String lastTimeStr = TimeUtils.convert(System.currentTimeMillis(), TimeUtils.TIME_FORMAT_YYYY_MM_DD_HH_MM_SS_2);
        viewBinding.tvLastTimeDemo.setText(lastTimeStr);

        viewBinding.layoutMenu1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ActivityLaunchUtils.launch(v.getContext(), NotificationActivity.class);
            }
        });

        viewBinding.btnExpFree.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ViewActivity.launch(v.getContext(), "16020017CD5FF40C6849F18B5BADB0A9", "体验账号");
            }
        });

        viewBinding.layoutBtnAddPhone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new AddFriendDialog().show();
            }
        });

    }

    @Override
    protected void loadData() {

    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEvent(UserLocEvent event) {

        String lastTimeStr = TimeUtils.convert(event.aMapLocation.getTime(), TimeUtils.TIME_FORMAT_YYYY_MM_DD_HH_MM_SS_2);
        viewBinding.tvLastTime.setText(lastTimeStr);

        viewBinding.tvMyLocation.setText(event.aMapLocation.getAddress());



    }

}
